{include file="common/head"}
<head>
    <title>{$type_name}管理</title>

    <style>
        a{text-decoration:none;}
        input{display:initial!important;}
    </style>
</head>
<body >
<div class="container-fluid">
    <form action="/index.php/customer/index" method="post">
        <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
            <div class="col-3" style="text-align: left;line-height: 50px;font-size: 2rem;" >
                <input type="hidden" name="show_grid" id="show_grid" value="{$show_grid}" />
                {$type_name}管理:{$list['total']}人
                
                <button type="button" class="btn btn-sm btn-primary" id="show_grid_change">
                    {if $show_grid!=1}
                        <span class="bi-grid"></span>
                    {else}
                        <span class="bi-table"></span>
                    {/if}
                </button>

            </div>
            <div class="col-9">

            <label for="type" >用户类型：</label>
            <select name="type" class="form-control" style="width:140px;display:initial;">
                <option value="">用户类型</option>
                {foreach $types as $k=>$v}
                    <option value="{$k}" >{$v}</option>
                {/foreach}
            </select>

            <label for="name" >姓名：</label>
            <input class="form-control" type="text"  id="name" name="name" value="{$name}" placeholder="姓名" />
            <label for="mobile" >手机：</label>
            <input class="form-control" type="text"  id="mobile" name="mobile" value="{$mobile}" placeholder="手机号码" />
            <button type="button" class="btn btn-warning query" style="vertical-align: middle;" >
                <span class="bi-search" ></span>
            </button>
            </div>
        </div>
    </form>
    {if $show_grid==1}
    <div id="cust_grid" style="display: flex;flex-wrap: wrap;">
        {foreach $list['data'] as $k=>$kv}
            <div class="cust_card row" style="width:300px;margin: 10px;box-shadow: 1px 1px 2px #444;padding:4px;">
                <div class="col-5">
                    <image class="goods_image" src="{$kv['image']}" style="width:100%;" />
                    <div style="color:blue;text-align:center;">{$kv['name']} </div>
                </div>
                <div class="col-7">
                    <div>手机：{$kv['mobile']} </div>
                    <div>邀请人：{$kv['inviter_name']} </div>
                    <div>进度：{$kv['status_name']} </div>
                    <div class="text-center">
                        <a href="/index.php/customer/edit/id/{$kv['id']}" title="编辑">
                            <button type="button" class="btn btn-sm btn-info" >
                                <span class="bi-pencil">编辑</span>
                            </button> 
                        </a>
                    <button type="buttun" onClick="resetPwd({$kv['id']})" class="btn btn-sm btn-danger" title="重置密码"> 
                        <span class="bi-key"></span>
                    </button>                        
                    </div>
                </div>
            </div>
        {/foreach}
    </div>

    {else}
    <table class="table table-sm table-hover table-striped">
        <thead>
            <th>序号</th>
            <!-- <th>{$type_name}编号</th> -->
            <th>姓名</th>
            <th>性别</th>
            <th>年龄</th>
            <th>电话</th>
            <th>微信</th>
            <th>现居地址</th>
            <th>推广人</th>            
            <th>登录时间</th>
            <th>状态</th>
            <th>
                <a href="/index.php/customer/customer_add" alt="新学员登记">
                <button type="button" class="btn btn-sm btn-primary">
                    <span class="bi-plus-lg" style="color:white;"></span>
                </button>
                </a>
            </th>
        </thead>
        <tbody>
            {foreach $list['data'] as $k=>$kv}
            <tr>
                <td>{$k+1}</td>
                <!-- <td>{$kv['id']}</td> -->

                <td><a href="/index.php/customer/edit/id/{$kv['id']}" title="编辑">
                    {$kv['name']}
                    </a>
                    {if $kv['money_check']>'1'}<c style="background-color:red;color:#fff; ">{$kv['money_check']}</c>{/if}

                </td>
                <td>{$kv['sex']}</td>
                <td>{$kv['age']}</td>
                <td>{$kv['mobile']}</td>
                <td>{$kv['wx']}</td>
                <td>{$kv['address']}</td>
                <!-- <td><img src="{$kv['image']}" class="goods_image" style="width:40px;" alt="无相片" /></td> -->
                <td>{$kv['inviter_name']}</td>
                <td title="ip:{$kv['login_ip']}">{$kv['login_time']}</td>
                <td><button type="button" class="btn btn-sm btn-st 
                    {if $kv['status']==2}btn-success
                    {elseif $kv['status']==3}btn-info
                    {elseif $kv['status']==4}btn-secondary
                    {elseif $kv['status']==5}btn-warning
                    {else}btn-primary
                    {/if}" cid="{$kv['id']}" cname="{$kv['name']}" status="{$kv['status']}" >{$kv['status_name']}</button></td> 
                <td>
                    <a href="/index.php/customer/edit/id/{$kv['id']}" title="编辑">
                        <button style="button" class="btn btn-sm btn-secondary"><span class="bi-pencil"></span></button>
                    </a>

                    <button type="buttun" onClick="resetPwd({$kv['id']})" class="btn btn-sm btn-danger" title="重置密码"> 
                        <span class="bi-key"></span>
                    </button>

<!--                     <button type="buttun"  class="btn btn-sm btn-info btn-more" title="更多资料" > 
                        <span class="bi-eye"></span>
                    </button> -->
              
                </td>
            </tr>
            {/foreach}
            
        </tbody>
    </table>
    {/if}

    {include file="common/pagination"}
</div>
<style>
    #mask{position: fixed;background: #000;opacity: 0.5;left:0;top:0;width:100%;height: 100%;display: none;z-index: 9;}
</style>
    <div id="mask"></div>
<div id="st_box"  style="border:1px solid #ccc;width:300px;position: fixed;left:40%;top:30%;background: #fff;display: none;z-index: 10;">
    <div class="text-center" style="font-size: 1.2rem;">学员考试进度选择【<c id="customer_name"></c>】</div>
    <div style="border-bottom: 1px solid #ccc;height: 10px;"></div>

    {foreach $status as $k=>$st}
    <div class="form-check" style="margin:4px 20px;">
      <input type="radio" class="form-check-input" id="radio{$k}" name="status" value="{$k}"  /> 
      <label class="form-check-label" for="radio{$k}" style="width:initial;">{$st}</label>
    </div>
    {/foreach}
    <input type="hidden" name="cid" id="cid" />
    <div style="border-top: 1px solid #ccc;text-align: center;padding: 5px;">
        <button type="button" class="btn btn-sm btn-primary btn-block" id="status_post"><span class="bi-check"></span>提交</button>
    </div>
</div>



</body>



<script type="text/javascript">

  function resetPwd(uid){
    if(!uid) return false;
    layer.confirm('是否确定重置帐号密码?', {btn: ['是的','不了']}, function(){
        $.post('/index.php/customer/resetpwd',{id:uid},function(res){layer.msg(res.msg)})
    }, function(){
        layer.msg("好的!");
        return 0;
    });    
  }

  $(document).ready(function(){
    $(".query").on('click',function(){
        var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2

        $("form").submit();
        layer.close(index);
    }) 


    //弹出进度选择框
    $(".btn-st").on('click',function(){
        var cid = $(this).attr('cid');
        $("#cid").val(cid);
        $("#customer_name").text($(this).attr('cname'));
        var st = $(this).attr('status');
        $("input[name='status'][value='"+st+"']").prop('checked','checked');
        $("#mask").show();
        $("#st_box").show();

    })

    $("#mask").on('click',function(){
        $("#st_box").hide();
        $(this).hide();
    })

    //提交进度
    $("#st_box").on('click',"#status_post",function(){
        var cid=$("#cid").val();
        if(!cid) return;

        var st=$("input[name='status']:checked").val();
        var msg='';
        console.log(cid+","+st);
        // if(st==3 || st==4){
        //     var msg = "学员科目"+(st-1)+"通过，如有邀请人，系统会计算推广费。\r\n";
        // }

      //询问框
      layer.confirm(msg+'是否确定提交科目进度?', {
        btn: ['确定','取消'] //按钮
      }, function(){
        
        $.post('/index.php/customer/status_update',{cid:cid,status:st},function(res){
            if(res.code){
                layer.msg(res.msg);
                location.reload();
            }
            
        })

      }, function(){
        layer.msg("好的!");
        return 0;
      });





    })

    $("#show_grid_change").on('click',function(){
        val =$("#show_grid").val();
        console.log(val);
        $("#show_grid").val(val*1>0?0:1);
        $('form').submit();
    })




    $(".goods_image").on('click',function(){
        var img = $(this).attr('src');
        if(!img.trim()) return;

        layer.open({
          type: 1,
          title:'',
          closeBtn: 0, //不显示关闭按钮
         // anim: 1,
          time: 5*1000,
          shadeClose: true, //开启遮罩关闭              
          skin: 'layui-layer-rim', 
          content: "<img src='"+img+"' style='height:100%'>"
        });
    })    



  })

</script>


</body>
</html>
